﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace QuanLyDiemSinhVien.Manager
{
    public class ClassData
    {
        #region CONSTRUCTORS
        public ClassData(string connectionString)
        {
            m_connectionString = connectionString;
        }
        #endregion

        #region ATTRIBUTES
        const string SQL_INSERT = "";
        const string SQL_UPDATE = "";
        const string SQL_DELETE = "";
        const string SQL_SELECTONE = "";
        const string SQL_SELECTALL = "";
        const string SQL_SEARCH = "";
        const string SQL_LOGIN = "";
        const string SQL_CheckExistsUserInfo = "";
        private string m_connectionString;
        #endregion

        #region METHODS
        /// <summary>
        /// Insert student with @studentID
        /// </summary>
        /// <param name="values">Provide true order for SQL query</param>
        /// <returns></returns>
        public int Insert(object[] values)
        {
            int i = (int)DataAccess.ExecuteGetParameter(m_connectionString, SQL_INSERT, "@classID", values, true);
            return i;
        }
        public bool Update(object[] values)
        {
            int i = DataAccess.ExecuteStoreProcedure(m_connectionString, SQL_UPDATE, values);
            return i > 0;
        }
        public bool Delete(object[] values)
        {
            int i = DataAccess.ExecuteNonQuery(m_connectionString, SQL_DELETE, values);
            return i > 0;
        }
        public DataTable Select(object[] values)
        {
            return DataAccess.FillTable(m_connectionString, SQL_SELECTONE, values, false);
        }
        public DataTable SelectAll()
        {
            return DataAccess.FillTable(m_connectionString, SQL_SELECTALL, true);
        }
        public DataTable Search(string condition, object[] values)
        {
            if (condition.IndexOf("WHERE") < 0) condition = " WHERE " + condition;
            return DataAccess.FillTable(m_connectionString, SQL_SEARCH + condition, values, false);
        }

        public object Login(object[] values)
        {
            DataTable dtb = DataAccess.FillTable(m_connectionString, SQL_LOGIN, values, true);
            var studentInfo = new StudentInfo(dtb);
            return studentInfo;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="values">Student ID</param>
        /// <returns></returns>
        public bool CheckExistsUserInfo(int values)
        {
            int i = DataAccess.ExecuteStoreProcedure(m_connectionString, SQL_CheckExistsUserInfo, values);
            return i > 0;
        }

        #endregion
    }
}
